﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Data.SqlClient;
using CSharpDesign.DAL;
using CSharpDesign.Scripts;
using CSharpDesign.BLL;

namespace CSharpDesign.Admin
{
    public partial class XiuGaiShangPin : System.Web.UI.Page
    {
        SqlHelper data = new SqlHelper();
        XiuGaiShangPinService pinService = new XiuGaiShangPinService();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DropDownList1.DataSource = data.GetDataReader("select * from ShangPinFenLei");
                DropDownList1.DataValueField = "id";
                DropDownList1.DataTextField = "name";
                DropDownList1.DataBind();
                string sql = "select * from ShangPin where SPID=" + Request.QueryString["id"].ToString();
                getdata(sql);
            }
        }
        private void getdata(string sql)
        {
            SqlDataReader dr = data.GetDataReader(sql);
            if (dr.Read())
            {
                title.Text = dr["SPName"].ToString();
                TextBox2.Text = dr["SPPrice"].ToString();
                TextBox3.Text = dr["SPNum"].ToString();
                content1.Value = dr["SPIntroduce"].ToString();
                pic.Text = dr["SPPhoto"].ToString();
                Image1.ImageUrl = "../files/" + dr["SPPhoto"].ToString();
                //   DropDownList1.Items.FindByValue(dr["ShangPinFenLeiID"].ToString()).Selected = true;
                // DropDownList1.Items.FindByText(dr["ShangPinFenLeiName"].ToString()).Selected = true;


                TextBox1.Text = dr["SPXingHao"].ToString();
                TextBox4.Text = dr["SPGuiGe"].ToString();
                TextBox5.Text = dr["SPDanWei"].ToString();

            }

        }
        protected void Button3_Click(object sender, EventArgs e)
        {
            string res;
            upload up = new upload();
            res = up.Up(file1, "../files/");
            this.Label1.Visible = true;
            this.Label1.Text = up.Resup[Convert.ToInt32(res)];
            this.pic.Text = up.s;
            Image1.ImageUrl = "../files/" + pic.Text;
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            string title = this.title.Text.ToString().Trim();
            string txtBox1 = TextBox1.Text;
            string txtBox2 = TextBox2.Text;
            string txtBox3 = TextBox3.Text;
            string content1 = this.content1.Value;
            string pic = this.pic.Text;
            string selectedValue = DropDownList1.SelectedValue;
            string text = DropDownList1.SelectedItem.Text;
            string txtBox4 = TextBox4.Text;
            string txtBox5 = TextBox5.Text;
            string id = Request.QueryString["id"].ToString();

            pinService.UpdateShangpin(title, txtBox1, txtBox2, txtBox3, content1, pic, selectedValue, text, txtBox4, txtBox5, id);

            //Alert.AlertAndRedirect("修改成功", "ShangPinGuanLi.aspx");
            //new Alert().Alertjs("修改成功");
            Response.Write("<script language='javascript'>alert('修改成功');history.back()</script>");
        }
    }

}